
import cookin from "js-cookie";
import router from "@/router";
import store from "@/store";
import http from "@/http";
import { ElMessage as $msg } from "element-plus";

const state = {
  user: "",
  LoginData: {},
};

const getters = {
  user(state) {
    return state.user;
  },
};
const mutations = {
  admins: (state, user) => {
    state.user = user;
  },
  Logout(state) {
    let data = {
      _gp: "admin",
      _mt: "info",
    };
    http.post(data).then((res) => {
      console.log(res);
      if (200 == res.errno) {
        //  this.$store.state
        let { taglist } = store.state.tagmodules;
        taglist.length = 1;
        state.user = {};
        cookin.remove("token");
        router.push("/Login");
        $msg.success({ message: "退出成功" });
      }
    });
  },
};
const actions = {
  admins: (context, user) => {
    context.commit("admins", user);
  },
  Logout(context) {
    context.commit("Logout");
  },
};
export default {
  state,
  mutations,
  actions,
  getters,
};
